package com.example.xianzhi.controller.api;

import cn.hutool.json.JSONUtil;
import com.example.xianzhi.entity.TbType;
import com.example.xianzhi.service.TypeService;
import com.example.xianzhi.service.impl.TypeServiceImpl;
import org.lanqiao.mvc.entity.YockMvcAnnotation;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@YockMvcAnnotation.Controller("/apl_Type")
public class Apl_TypeController {

    private TypeService type = new TypeServiceImpl();

    /**
     * 查询分类列表
     * @param request
     * @param response
     * @return
     */
    @YockMvcAnnotation.RequestMapping("/selectype.do")
    @YockMvcAnnotation.ResponseBody
    public String selectype(
            HttpServletRequest request,
            HttpServletResponse response
    ) {
        //告诉前端返回来的是一个json数据
        response.setContentType("application/json;charset=utf-8");
        // 保存分类信息的集合
        Map<String, Object> map = new HashMap<>();
        //查询分类
        List<TbType> tbTypes = type.selectType();

        map.put("code",200);
        map.put("data",tbTypes);

        String jsonStr = JSONUtil.toJsonStr(map);


        return jsonStr;
    }





}
